<?php
$server = new Swoole\Http\Server("0.0.0.0", 9501);
$server->set([
    'task_worker_num' => 4,
]);
$server->on("request",function (\Swoole\Http\Request $request,\Swoole\Http\Response $response)use($server){
    $server->task("hello world");
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});


$server->on("task",function (\Swoole\Http\Server $serv, $task_id, $from_id, $data){
    echo "任务id:{$task_id}-正在执行任务...".PHP_EOL;
    sleep(5);
    return  "任务id:{$task_id}-任务执行完成".PHP_EOL;
});
$server->on("finish",function (\Swoole\Http\Server $serv, $task_id, $data){
    echo $data;
});
$server->start();